. /etc/init.d/functions
FILE_PATH=/root/aa.log
[ ! -f $FILE_PATH ] && touch $FILE_PATH
function usage()
{
    cat <<EOF

    USAGE: `basename $0` {-add|-del|-search} username
EOF
}
if [ $UID -ne 0 ];then
    echo -e "\E[1;31mPlease use root!\E[0m"
    exit 1
fi
if [ $# -ne 2 ];then
    usage
    exit 2
fi
function opera()
{
    case "$1" in
        -a|-add)
            shift
            if grep "^$1$" ${FILE_PATH} >/dev/null 2>&1
            then
                action $"vpnuser,$1 is exits" /bin/false
                exit
            else
                chattr -i ${FILE_PATH}
                /bin/cp ${FILE_PATH} ${FILE_PATH}.$(date +%F%T)
                echo "$1" >> ${FILE_PATH}
                [ $? -eq 0 ] && action $"ADD $1" /bin/true
                chattr +i ${FILE_PATH}
            fi
            ;;
        -d|-del)
            shift
            if [ `grep "\b$1\b" ${FILE_PATH} | wc -l` -lt 1 ]
            then
                action $"${FILE_PATH}, $1 is not exits" /bin/false
                exit
            else
                chattr -i ${FILE_PATH}
                /bin/cp ${FILE_PATH} ${FILE_PATH}.$(date +%F%T)
                sed -i "/^${1}$/d" ${FILE_PATH}
                [ $? -eq 0 ] && action $"DEL $1" /bin/true
                chattr +i ${FILE_PATH}
                exit
            fi
            ;;
        -s|-search)
            shift
            if [ `grep -w "$1" ${FILE_PATH} | wc -l` -lt 1 ]
            then
                echo "$1 is not exits";exit
            else
                echo "$1 is exits";exit
            fi
            ;;
        *)
            usage
            exit
            ;;
    esac
}
function main()
{
    opera $1 $2
}
main $*